package com.lino.design;

import com.lino.design.store.ICommodity;
import com.lino.design.store.impl.CardCommodityService;
import com.lino.design.store.impl.CouponCommodityService;
import com.lino.design.store.impl.GoodsCommodityService;

/**
 * @description: 奖品工厂
 * @author: lingjian
 * @createDate: 2022/12/16 8:42
 */
public class StoreFactory {

    /**
     * 奖品类型方式实例化
     *
     * @param commodityType 奖品类型
     * @return 实例化对象
     */
    public ICommodity getCommodityService(Integer commodityType) {
        if (null == commodityType) {
            return null;
        }
        if (1 == commodityType) {
            return new CouponCommodityService();
        }
        if (2 == commodityType) {
            return new GoodsCommodityService();
        }
        if (3 == commodityType) {
            return new CardCommodityService();
        }
        throw new RuntimeException("不存在的奖品服务类型");
    }

    /**
     * 奖品类信息方法实例化
     *
     * @param clazz 奖品类
     * @return 实例化对象
     * @throws InstantiationException
     * @throws IllegalAccessException
     */
    public ICommodity getCommodityService(Class<? extends ICommodity> clazz) throws InstantiationException, IllegalAccessException {
        if (null == clazz) {
            return null;
        }
        return clazz.newInstance();
    }

}
